package com.yami.shop.rights.api;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.rights.common.dto.RightsRecordDto;
import com.yami.shop.rights.common.service.PersonRightsService;
import com.yami.shop.rights.common.service.RightsRecordService;
import com.yami.shop.rights.common.strategy.PersonRightsFactory;
import com.yami.shop.rights.common.vo.ProdRightDetailVo;
import com.yami.shop.rights.common.vo.ProdRightsVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController("rightsNoTokenController")
@RequestMapping("/app/rights")
@Tag(name = "app-rightsNoToken信息")
@AllArgsConstructor
public class RightsNoTokenController {

    @Autowired
    private PersonRightsService personRightsService;
    @Autowired
    private PersonRightsFactory personRightsFactory;
    @Autowired
    private RightsRecordService rightsRecordService;


    /**
     *
     * @param page
     * @param status 0 未使用 1 使用 3 过期
     * @return
     */
    @GetMapping("/getNoUseRightsLists")
    public ServerResponseEntity<IPage<ProdRightDetailVo>> getNoUseRightsLists(PageParam<ProdRightDetailVo> page,Integer status,String userId){
        IPage<ProdRightDetailVo> list = personRightsFactory.getNoUseRightsLists(page,status,userId);
        return ServerResponseEntity.success(list);
    }
    /**
     *
     * @param page 使用记录
     * @param
     * @return
     */
    @GetMapping("/page" )
    @Operation(summary =  "分页权益核销记录", description = "分页权益核销记录")
    public ServerResponseEntity<IPage<RightsRecordDto>> getUserBalanceLogPage(PageParam<RightsRecordDto> page, String type, String userId) {
        if(ObjectUtil.isEmpty(type)){
            throw new YamiShopBindException("查询类型不能为空");
        }
        IPage<RightsRecordDto> rightsRecordDtoIPage = rightsRecordService.getRightsRecord(page, userId,type);
        return ServerResponseEntity.success(rightsRecordDtoIPage);
    }

    /**
     * 获取实物兑换商品详情
     * @param personRightsId
     * @return
     */
    @GetMapping("/getProdInfoByPersonRightsId")
    public ServerResponseEntity<ProdRightsVo> getProdInfoByPersonRightsId(Long personRightsId){
        ProdRightsVo prodRightsVo = personRightsService.getProdInfoByPersonRightsId(personRightsId);
        return ServerResponseEntity.success(prodRightsVo);
    }


    /**
     * 功能描述: 可核销权益详细信息
     * @Author: LSR
     * @Date: 2023/6/12 11:30
     */
    // 当前版本 一个 权益绑定一个券 如 多个券 加参数
    @GetMapping("/getProdRightsById")
    public ServerResponseEntity<ProdRightsVo> getProdRightsById(Long personRightsId,String userId){
        ProdRightsVo prodRightsVo = personRightsService.getProdRightsById(personRightsId,userId);
        return ServerResponseEntity.success(prodRightsVo);
    }
}
